<template>
    <div id="box">
<el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
  <el-form-item label="账号" prop="username">
    <el-input type="text" v-model="ruleForm.username" autocomplete="off"></el-input>
  </el-form-item>
  <el-form-item label="密码" prop="pass">
    <el-input type="password" v-model="ruleForm.pass" autocomplete="off"></el-input>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
    <el-button @click="resetForm('ruleForm')">重置</el-button>
  </el-form-item>
</el-form>

    </div>
</template>

<script>
import http from 'axios'
export default {
    data() {
     
      var validatePass = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请输入账号'));
        }
          callback();
      };
      var validatePass2 = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请再次输入密码'));
        }
          callback();
      };
      return {
        ruleForm: {
          username: '',
          pass: '',
       
        },
        rules: {
          username: [
            { validator: validatePass, trigger: 'blur' }
          ],
          pass: [
            { validator: validatePass2, trigger: 'blur' }
          ],
        
        }
      };
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            const parnms = {
                username:this.ruleForm.username,
                pass:this.ruleForm.pass
            }
            console.log(parnms);
            http.post('http://estate.eshareedu.cn/estate/api/administrator/checklogin',parnms).then((res)=>{
              console.log(res);
                    const {token,errCode} = res.data
                    if(errCode == 10000){
                        console.log(444)
                        this.$message.success('登陆成功'),
                        sessionStorage.setItem('token',res.data.data.token)
                        this.$store.commit('menu/SET_LIST', res.data.data.menu)
                        this.$router.push('/index')
                    }else{
                        console.log(222)
                    }
            })
          } else {
            console.log(555);
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  }
</script>

<style>

.demo-ruleForm{
    width: 500px;
    height: 200px;
  background: rgba(55, 55, 55, 0.5);
  padding-right: 50px;
  padding-top: 20px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%,-50%);
  }
  #box{
    width: 100%;
    height: 100%;
    background-color: powderblue;
    z-index: 1;
    position: absolute;
  }
</style>